from aip import AipOcr


APP_ID = "23034499"
APP_KEY = "vflWnjwg5WzYHUci34Q8GvzE"
SECRET_KEY = "QRxhSB2GPzgNXcMyDWYHgBzgVjqsjsHw"

client = AipOcr(APP_ID, APP_KEY, SECRET_KEY)

def get_file(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

def Identify_Code(filePath):
    img = get_file(filePath)
    options = {}
    options["language_type"] = "ENG"
    val=client.basicAccurate(img,options)
    code = (val['words_result'][0]['words'])
    #code = code.replace(" ","")
    code  = "".join([x for x in code if x.isalnum()])
    print(code)
    #if len(code) == 7:
    return code
    #return ""

if __name__ == "__main__":
    Identify_Code("out.png")
    Identify_Code("code.png")
